/*******************************************************************************
 * Copyright (c) 2012, 2013 XML-Print Project.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     XML-Print Project - initial API and implementation
 ******************************************************************************/
package info.xmlprint.ui.format;

import java.util.HashMap;

import info.xmlprint.core.format.Format;
import info.xmlprint.run.RuntimeUtil;
import info.xmlprint.ui.message.GuiMessages;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class ParagraphComposite extends GuiCommon implements IFormatSetup {
	private Composite comp;

	private Combo comboAlignment;// text_align

	private String[] comboAlignmentItems_local;

	private Spinner spinnerMarginLeft;// margin_left
	private Combo comboMarginLeftUnit; // unit

	private Spinner spinnerMarginRight; // margin_right
	private Combo comboMarginRight;// unit

	private Combo comboSpecialIndent;// text_indent
	private Spinner spinnerSpecialIndent;// unit

	private Spinner spinnerSpacingBeforeOptimum;// space_before_optimum
	private Combo comboSpacingBeforeOptimumUnit;// unit

	private Combo comboSpacingAfterOptimumUnit;// space_after_optimum
	private Spinner spinnerSpacingAfterOptimum;// unit

	private Spinner spinnerSpacingBeforeMinimum;

	private Button buttonSpacingAfterMinimum;
	private Button buttonSpacingAfterMaximum;
	private Label labelSpacingAfterOptimum;

	private Combo comboSpacingAfterMinimumUnit;
	private Spinner spinnerSpacingAfterMinimum;
	private Combo comboSpacingAfterMaximumUnit;
	private Spinner spinnerSpacingAfterMaximum;

	private Combo comboSpacingBeforeMinimumUnit;
	private Combo comboSpacingBeforeMaximumUnit;
	private Spinner spinnerSpacingBeforeMaximum;

	private Button buttonSpacingBeforeMinimum;
	private Button buttonSpacingBeforeMaximum;
	private Label labelSpaceOptimal;

	private Format format, formatForSetup;
	
	private Group groupColumnSelection;
	private Label columncountLabel;
	private Combo comboColumncount;
	
	private Combo comboOpenNewpage;
	private String[] comboOpenNewpageItems_local;

	private Combo comboPageMaster;
	private String[] comboPageMasterItems_local;

	/**
	 * gui testen
	 */
	public static void main(String[] args) {
		Display display = Display.getDefault();
		Shell shell = new Shell(display);
		new ParagraphComposite(shell, SWT.NULL, new Format());

		shell.setLayout(new FillLayout());
		shell.layout();

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	public ParagraphComposite(org.eclipse.swt.widgets.Composite parent, int style,
			Format f) {
		format = f;
		formatForSetup = format.objClone();

		comp = new Composite(parent, style);

		languageInit();
		initGUI();

	}

	private void languageInit() {
		// text-align
		{
			String original[] = new String[] { "justify", "left", "right",
					"center" };

			comboAlignmentItems_local = new java.lang.String[] {
					GuiMessages.Stileditor_ParagraphFormat_Alignment_Justified,
					GuiMessages.Stileditor_ParagraphFormat_Alignment_Left,
					GuiMessages.Stileditor_ParagraphFormat_Alignment_Right,
					GuiMessages.Stileditor_ParagraphFormat_Alignment_Center };

			addInternationalMap("text-align", original,
					comboAlignmentItems_local);
		}
		
		{
			String original[] = new String[] { "auto", "page", "odd-page", "even-page", "column" };
			
			comboOpenNewpageItems_local = new String[] {
					GuiMessages.Stileditor_ParagraphFormat_Pagemaster_Open_None,
					GuiMessages.Stileditor_ParagraphFormat_Pagemaster_Open_Any,
					GuiMessages.Stileditor_ParagraphFormat_Pagemaster_Open_Right,
					GuiMessages.Stileditor_ParagraphFormat_Pagemaster_Open_Left,
					GuiMessages.Stileditor_ParagraphFormat_Pagemaster_Open_Column
			};
			
			addInternationalMap("break-after", original,
					comboOpenNewpageItems_local);
		}
		
		
	}

	private void initGUI() {
		comp.setLayout(new GridLayout(9, false));
		{
			// Ausrichtung
			addLabel(comp, GuiMessages.Stileditor_ParagraphFormat_Alignment
					+ ":");
			comboAlignment = new Combo(comp, SWT.NONE);
			comboAlignment.setLayoutData(getGD(0, 2, 140, 0));
			comboAlignment.setItems(comboAlignmentItems_local);
			comboAlignment.select(0);

			// add inherit Checkbox
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));

			// add Standard Checkbox
			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 5, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> hm = new HashMap<String, Control[]>();
			hm.put("text-align", new Control[] { comboAlignment });

			controlsInit(standardButton, inheritButton, hm, null,
					formatForSetup);

		}

		{
			// Links
			addLabel(comp,
					GuiMessages.Stileditor_ParagraphFormat_Indention_Left + ":");

			spinnerMarginLeft = new Spinner(comp, SWT.NONE);
			spinnerMarginLeft.setDigits(2);
			spinnerMarginLeft.setLayoutDeferred(true);
			spinnerMarginLeft.setLayoutData(getGD(0, 1, 50, 0));
			spinnerMarginLeft.setMaximum(10000);
			spinnerMarginLeft.setIncrement(10);

			comboMarginLeftUnit = new Combo(comp, SWT.NONE);
			comboMarginLeftUnit.setLayoutData(getGD(0, 1, 70, 0));
			comboMarginLeftUnit.setItems(itemListUnits);
			// comboMarginLeftUnit.select(0);

			// add inherit Checkbox
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));

			// add Standard Checkbox
			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 5, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> hm = new HashMap<String, Control[]>();
			hm.put("margin-left", new Control[] { spinnerMarginLeft,
					comboMarginLeftUnit });
			controlsInit(standardButton, inheritButton, hm, null,
					formatForSetup);
		}
		{
			// Rechts
			addLabel(comp,
					GuiMessages.Stileditor_ParagraphFormat_Indention_Right
							+ ":");
			spinnerMarginRight = new Spinner(comp, SWT.NONE);
			spinnerMarginRight.setLayoutData(getGD(0, 1, 50, 0));
			spinnerMarginRight.setDigits(2);
			spinnerMarginRight.setMaximum(10000);
			spinnerMarginRight.setIncrement(10);

			comboMarginRight = new Combo(comp, SWT.NONE);
			comboMarginRight.setLayoutData(getGD(0, 1, 70, 0));
			comboMarginRight.setItems(itemListUnits);
			// comboMarginRight.select(0);

			// add inherit Checkbox
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));
			// add Standard Checkbox

			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 5, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> hm = new HashMap<String, Control[]>();
			hm.put("margin-right", new Control[] { spinnerMarginRight,
					comboMarginRight });
			controlsInit(standardButton, inheritButton, hm, null,
					formatForSetup);
		}
		{
			// text-indent
			addLabel(comp,
					GuiMessages.Stileditor_ParagraphFormat_SpecialIndention
							+ ":");
			spinnerSpecialIndent = new Spinner(comp, SWT.NONE);
			spinnerSpecialIndent.setLayoutData(getGD(0, 1, 50, 0));
			spinnerSpecialIndent.setDigits(2);
			spinnerSpecialIndent.setMinimum(-10000);
			spinnerSpecialIndent.setMaximum(10000);
			spinnerSpecialIndent.setIncrement(10);

			comboSpecialIndent = new Combo(comp, SWT.NONE);
			comboSpecialIndent.setLayoutData(getGD(0, 1, 70, 0));
			comboSpecialIndent.setItems(itemListUnits);
			// comboSpecialIndent.select(0);

			// add inherit Checkbox
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));

			// add Standard Checkbox

			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 5, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> hm = new HashMap<String, Control[]>();
			hm.put("text-indent", new Control[] { spinnerSpecialIndent,
					comboSpecialIndent });
			controlsInit(standardButton, inheritButton, hm, null,
					formatForSetup);
		}
		{
			// empty line
			new Label(comp, SWT.NONE).setLayoutData(getGD(0, 9, 70, 0));
		}
		{

			/*
			 * new Label(comp, SWT.NONE).setLayoutData(getGD(0, 1, 23, 0));
			 * 
			 * // Before Optimal Title GridData labelSpacingBeforeOptimalLData =
			 * new GridData(); labelSpacingBeforeOptimalLData.horizontalSpan =
			 * 2; labelSpacingBeforeOptimalLData.horizontalAlignment =
			 * GridData.CENTER; labelSpacingBeforeOptimalLData.widthHint = 55;
			 * //labelSpacingBeforeOptimalLData.heightHint = 13;
			 * labelSpaceOptimal = new Label(comp, SWT.NONE);
			 * labelSpaceOptimal.setLayoutData(labelSpacingBeforeOptimalLData);
			 * labelSpaceOptimal
			 * .setText(GuiMessages.Stileditor_ParagraphFormat_Optimum);
			 * 
			 * /* Disabled till feature is supported by the typesetting engine
			 * // Before Maximum Checkbox buttonSpacingBeforeMaximum = new
			 * Button(comp, SWT.CHECK | SWT.LEFT); GridData
			 * buttonSpacingBeforeMaximumLData = new GridData();
			 * buttonSpacingBeforeMaximumLData.horizontalAlignment =
			 * GridData.CENTER; buttonSpacingBeforeMaximumLData.horizontalSpan =
			 * 2; buttonSpacingBeforeMaximum
			 * .setLayoutData(buttonSpacingBeforeMaximumLData);
			 * buttonSpacingBeforeMaximum
			 * .setText(GuiMessages.Stileditor_ParagraphFormat_Maximum);
			 * buttonSpacingBeforeMaximum .addSelectionListener(new
			 * SelectionAdapter() { public void widgetSelected(SelectionEvent
			 * evt) { spinnerSpacingBeforeMaximum
			 * .setEnabled(buttonSpacingBeforeMaximum .getSelection()); // 0
			 * setzen // if (!buttonSpacingBeforeMaximum.getSelection()) //
			 * spinnerSpacingBeforeMaximum.setSelection(0);
			 * 
			 * comboSpacingBeforeMaximumUnit
			 * .setEnabled(buttonSpacingBeforeMaximum .getSelection());
			 * 
			 * }
			 * 
			 * }); // Before Minimum Checkbox buttonSpacingBeforeMinimum = new
			 * Button(comp, SWT.CHECK | SWT.LEFT); GridData
			 * buttonSpacingBeforeMinimumLData = new GridData();
			 * buttonSpacingBeforeMinimumLData.horizontalSpan = 2;
			 * buttonSpacingBeforeMinimumLData.horizontalAlignment =
			 * GridData.CENTER; buttonSpacingBeforeMinimum
			 * .setLayoutData(buttonSpacingBeforeMinimumLData);
			 * buttonSpacingBeforeMinimum
			 * .setText(GuiMessages.Stileditor_ParagraphFormat_Minimum);
			 * buttonSpacingBeforeMinimum .addSelectionListener(new
			 * SelectionAdapter() { public void widgetSelected(SelectionEvent
			 * evt) { spinnerSpacingBeforeMinimum
			 * .setEnabled(buttonSpacingBeforeMinimum .getSelection());
			 * 
			 * // 0 setzen // if (!buttonSpacingBeforeMinimum.getSelection()) //
			 * spinnerSpacingBeforeMinimum.setSelection(0);
			 * 
			 * comboSpacingBeforeMinimumUnit
			 * .setEnabled(buttonSpacingBeforeMinimum .getSelection()); }
			 * 
			 * }); addLabel(comp, ""); addLabel(comp, "");
			 */
		}

		{
			// spacing before
			addLabel(comp,
					GuiMessages.Stileditor_ParagraphFormat_Spacing_Before + ":");

			// Before Optimum Spinnner-Combo
			spinnerSpacingBeforeOptimum = new Spinner(comp, SWT.NONE);
			spinnerSpacingBeforeOptimum.setLayoutData(getGD(0, 1, 50, 0));
			spinnerSpacingBeforeOptimum.setDigits(2);
			spinnerSpacingBeforeOptimum.setIncrement(10);
			spinnerSpacingBeforeOptimum.setMaximum(10000);

			/*
			 * spinnerSpacingBeforeOptimum.addListener(SWT.Selection, new
			 * Listener() { public void handleEvent(Event e) { if
			 * (spinnerSpacingBeforeOptimum.getSelection() >
			 * spinnerSpacingBeforeMaximum .getSelection()) {
			 * spinnerSpacingBeforeMaximum
			 * .setSelection(spinnerSpacingBeforeOptimum .getSelection()); } if
			 * (spinnerSpacingBeforeOptimum.getSelection() <
			 * spinnerSpacingBeforeMinimum .getSelection()) {
			 * spinnerSpacingBeforeMinimum
			 * .setSelection(spinnerSpacingBeforeOptimum .getSelection()); }
			 * spinnerSpacingBeforeMaximum
			 * .setMinimum(spinnerSpacingBeforeOptimum .getSelection());
			 * spinnerSpacingBeforeMinimum
			 * .setMaximum(spinnerSpacingBeforeOptimum .getSelection()); } });
			 */

			comboSpacingBeforeOptimumUnit = new Combo(comp, SWT.NONE);
			comboSpacingBeforeOptimumUnit.setLayoutData(getGD(0, 1, 70, 0));
			comboSpacingBeforeOptimumUnit.setItems(itemListUnits);
			// comboSpacingBeforeOptimumUnit.select(0);

			/*
			 * // Before Maximun Spinnner-Combo // spinner
			 * spinnerSpacingBeforeMaximum = new Spinner(comp, SWT.NONE);
			 * spinnerSpacingBeforeMaximum.setLayoutData(getGD(0, 1, 50, 0));
			 * spinnerSpacingBeforeMaximum.setDigits(2);
			 * spinnerSpacingBeforeMaximum.setIncrement(10);
			 * spinnerSpacingBeforeMaximum.setMaximum(10000); if
			 * (!buttonSpacingBeforeMaximum.getSelection()) {
			 * spinnerSpacingBeforeMaximum.setEnabled(false); }
			 * 
			 * comboSpacingBeforeMaximumUnit = new Combo(comp, SWT.NONE);
			 * comboSpacingBeforeMaximumUnit.setLayoutData(getGD(0, 1, 70, 0));
			 * comboSpacingBeforeMaximumUnit.setItems(itemListUnits); if
			 * (!buttonSpacingBeforeMaximum.getSelection()) {
			 * comboSpacingBeforeMaximumUnit.setEnabled(false); } //
			 * comboSpacingBeforeMaximumUnit.select(0);
			 * 
			 * // Before Minimum Spinnner-Combo // spinner
			 * spinnerSpacingBeforeMinimum = new Spinner(comp, SWT.NONE);
			 * spinnerSpacingBeforeMinimum.setLayoutData(getGD(0, 1, 50, 0));
			 * spinnerSpacingBeforeMinimum.setDigits(2);
			 * spinnerSpacingBeforeMinimum.setIncrement(10);
			 * spinnerSpacingBeforeMinimum.setMaximum(10000); if
			 * (!buttonSpacingBeforeMinimum.getSelection()) {
			 * spinnerSpacingBeforeMinimum.setEnabled(false); } // combo
			 * comboSpacingBeforeMinimumUnit = new Combo(comp, SWT.NONE);
			 * comboSpacingBeforeMinimumUnit.setLayoutData(getGD(0, 1, 70, 0));
			 * comboSpacingBeforeMinimumUnit.setItems(itemListUnits); if
			 * (!buttonSpacingBeforeMinimum.getSelection()) {
			 * comboSpacingBeforeMinimumUnit.setEnabled(false); } //
			 * comboSpacingBeforeMinimumUnit.select(0);
			 */

			// add inherit Checkbox
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));

			// add Standard Checkbox
			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 1, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> hm = new HashMap<String, Control[]>();
			hm.put("space-before.optimum",
					new Control[] { spinnerSpacingBeforeOptimum,
							comboSpacingBeforeOptimumUnit });
			/*
			 * hm.put("space-before.maximum", new Control[] {
			 * spinnerSpacingBeforeMaximum, comboSpacingBeforeMaximumUnit });
			 * hm.put("space-before.minimum", new Control[] {
			 * spinnerSpacingBeforeMinimum, comboSpacingBeforeMinimumUnit });
			 */
			HashMap<String, Control> buttonMap = new HashMap<String, Control>();
			/*
			 * buttonMap.put("space-before.maximum",
			 * buttonSpacingBeforeMaximum);
			 * buttonMap.put("space-before.minimum",
			 * buttonSpacingBeforeMinimum);
			 */

			controlsInit(standardButton, inheritButton, hm, buttonMap,
					formatForSetup);
		}

		{
			// leere Zeile
			new Label(comp, SWT.NONE).setLayoutData(getGD(0, 9, 70, 0));
		}

		{
			/*
			 * new Label(comp, SWT.NONE).setLayoutData(getGD(0, 1, 23, 0));
			 * 
			 * // AfterOptimum Title labelSpacingAfterOptimum = new Label(comp,
			 * SWT.NONE); GridData labelSpacingAfterOptimalLData = new
			 * GridData(); labelSpacingAfterOptimalLData.horizontalSpan = 2;
			 * labelSpacingAfterOptimalLData.horizontalAlignment =
			 * GridData.CENTER; labelSpacingAfterOptimalLData.widthHint = 55;
			 * //labelSpacingAfterOptimalLData.heightHint = 13;
			 * labelSpacingAfterOptimum
			 * .setLayoutData(labelSpacingAfterOptimalLData);
			 * labelSpacingAfterOptimum
			 * .setText(GuiMessages.Stileditor_ParagraphFormat_Optimum);
			 * 
			 * // AfterMaximum Checkbox buttonSpacingAfterMaximum = new
			 * Button(comp, SWT.CHECK | SWT.LEFT); GridData
			 * buttonSpacingAfterMaximumLData = new GridData();
			 * buttonSpacingAfterMaximumLData.horizontalSpan = 2;
			 * buttonSpacingAfterMaximumLData.horizontalAlignment =
			 * GridData.CENTER; buttonSpacingAfterMaximum
			 * .setLayoutData(buttonSpacingAfterMaximumLData);
			 * buttonSpacingAfterMaximum
			 * .setText(GuiMessages.Stileditor_ParagraphFormat_Maximum);
			 * buttonSpacingAfterMaximum .addSelectionListener(new
			 * SelectionAdapter() { public void widgetSelected(SelectionEvent
			 * evt) { spinnerSpacingAfterMaximum
			 * .setEnabled(buttonSpacingAfterMaximum .getSelection()); // 0
			 * setzen if (!buttonSpacingAfterMaximum.getSelection())
			 * spinnerSpacingAfterMaximum.setSelection(0);
			 * 
			 * comboSpacingAfterMaximumUnit
			 * .setEnabled(buttonSpacingAfterMaximum .getSelection()); }
			 * 
			 * });
			 * 
			 * // AfterMinimum Checkbox buttonSpacingAfterMinimum = new
			 * Button(comp, SWT.CHECK | SWT.LEFT); GridData
			 * buttonSpacingAfterMinimumLData = new GridData();
			 * buttonSpacingAfterMinimumLData.horizontalSpan = 2;
			 * buttonSpacingAfterMinimumLData.horizontalAlignment =
			 * GridData.CENTER; buttonSpacingAfterMinimum
			 * .setLayoutData(buttonSpacingAfterMinimumLData);
			 * buttonSpacingAfterMinimum
			 * .setText(GuiMessages.Stileditor_ParagraphFormat_Minimum);
			 * buttonSpacingAfterMinimum .addSelectionListener(new
			 * SelectionAdapter() { public void widgetSelected(SelectionEvent
			 * evt) { spinnerSpacingAfterMinimum
			 * .setEnabled(buttonSpacingAfterMinimum .getSelection());
			 * 
			 * // 0 setzen if (!buttonSpacingAfterMinimum.getSelection())
			 * spinnerSpacingAfterMinimum.setSelection(0);
			 * 
			 * comboSpacingAfterMinimumUnit
			 * .setEnabled(buttonSpacingAfterMinimum .getSelection()); } });
			 * addLabel(comp, ""); addLabel(comp, "");
			 */
		}

		{
			// spacing after
			addLabel(comp, GuiMessages.Stileditor_ParagraphFormat_Spacing_After
					+ ":");

			// AfterOptimum Spinnner-Combo
			// spinner
			spinnerSpacingAfterOptimum = new Spinner(comp, SWT.NONE);
			spinnerSpacingAfterOptimum.setLayoutData(getGD(0, 1, 50, 0));
			spinnerSpacingAfterOptimum.setDigits(2);
			spinnerSpacingAfterOptimum.setIncrement(10);
			spinnerSpacingAfterOptimum.setMaximum(10000);

			// combo
			comboSpacingAfterOptimumUnit = new Combo(comp, SWT.NONE);
			comboSpacingAfterOptimumUnit.setLayoutData(getGD(0, 1, 70, 0));
			comboSpacingAfterOptimumUnit.setItems(itemListUnits);

			/*
			 * spinnerSpacingAfterOptimum.addListener(SWT.Selection, new
			 * Listener() { public void handleEvent(Event e) { if
			 * (spinnerSpacingAfterOptimum.getSelection() >
			 * spinnerSpacingAfterMaximum .getSelection()) {
			 * spinnerSpacingAfterMaximum
			 * .setSelection(spinnerSpacingAfterOptimum .getSelection()); } if
			 * (spinnerSpacingAfterOptimum.getSelection() <
			 * spinnerSpacingAfterMinimum .getSelection()) {
			 * spinnerSpacingAfterMinimum
			 * .setSelection(spinnerSpacingAfterOptimum .getSelection()); }
			 * spinnerSpacingAfterMaximum .setMinimum(spinnerSpacingAfterOptimum
			 * .getSelection()); spinnerSpacingAfterMinimum
			 * .setMaximum(spinnerSpacingAfterOptimum .getSelection()); } });
			 * 
			 * // AfterMaximum Spinnner-Combo // spinner
			 * spinnerSpacingAfterMaximum = new Spinner(comp, SWT.NONE);
			 * spinnerSpacingAfterMaximum.setLayoutData(getGD(0, 1, 50, 0));
			 * spinnerSpacingAfterMaximum.setDigits(2);
			 * spinnerSpacingAfterMaximum.setIncrement(10);
			 * spinnerSpacingAfterMaximum.setMaximum(10000); if
			 * (!buttonSpacingAfterMaximum.getSelection()) {
			 * spinnerSpacingAfterMaximum.setEnabled(false); } // combo
			 * comboSpacingAfterMaximumUnit = new Combo(comp, SWT.NONE);
			 * comboSpacingAfterMaximumUnit.setLayoutData(getGD(0, 1, 70, 0));
			 * comboSpacingAfterMaximumUnit.setItems(itemListUnits); if
			 * (!buttonSpacingAfterMaximum.getSelection()) {
			 * comboSpacingAfterMaximumUnit.setEnabled(false); } //
			 * comboSpacingAfterMaximumUnit.select(0);
			 * 
			 * // AfterMinimum Spinnner-Combo // spinner
			 * spinnerSpacingAfterMinimum = new Spinner(comp, SWT.NONE);
			 * spinnerSpacingAfterMinimum.setLayoutData(getGD(0, 1, 50, 0));
			 * spinnerSpacingAfterMinimum.setDigits(2);
			 * spinnerSpacingAfterMinimum.setIncrement(10);
			 * spinnerSpacingAfterMinimum.setMaximum(10000); if
			 * (!buttonSpacingAfterMinimum.getSelection()) {
			 * spinnerSpacingAfterMinimum.setEnabled(false); }
			 * 
			 * // Combo comboSpacingAfterMinimumUnit = new Combo(comp,
			 * SWT.NONE); comboSpacingAfterMinimumUnit.setLayoutData(getGD(0, 1,
			 * 70, 0)); comboSpacingAfterMinimumUnit.setItems(itemListUnits); if
			 * (!buttonSpacingAfterMinimum.getSelection()) {
			 * comboSpacingAfterMinimumUnit.setEnabled(false); } //
			 * comboSpacingAfterMinimumUnit.select(0);
			 */
			// add inherit Checkbox
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));

			// add Standard Checkbox
			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 1, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> controlMap = new HashMap<String, Control[]>();
			controlMap.put("space-after.optimum", new Control[] {
					spinnerSpacingAfterOptimum, comboSpacingAfterOptimumUnit });
			/*
			 * controlMap.put("space-after.maximum", new Control[] {
			 * spinnerSpacingAfterMaximum, comboSpacingAfterMaximumUnit });
			 * controlMap.put("space-after.minimum", new Control[] {
			 * spinnerSpacingAfterMinimum, comboSpacingAfterMinimumUnit });
			 */

				HashMap<String, Control> buttonMap = new HashMap<String, Control>();
			/*
			 * buttonMap.put("space-after.maximum", buttonSpacingAfterMaximum);
			 * buttonMap.put("space-after.minimum", buttonSpacingAfterMinimum);
			 */

			controlsInit(standardButton, inheritButton, controlMap, buttonMap,
					formatForSetup);

		}
		
		{
			// leere Zeile
			new Label(comp, SWT.NONE).setLayoutData(getGD(0, 9, 70, 0));
		}
		
		{
			// new page
			//Group breakgroup = new Group(comp, SWT.NONE);
			//breakgroup.setText(GuiMessages.Stileditor_ParagraphFormat_Pagemaster);
			addLabel(comp, GuiMessages.Stileditor_ParagraphFormat_Pagemaster_Open);
			
			comboOpenNewpage = new Combo(comp, SWT.NONE);
			comboOpenNewpage.setLayoutData(getGD(0, 2, 140, 0));
			comboOpenNewpage.setItems(comboOpenNewpageItems_local);
			comboOpenNewpage.select(0);
			
			addLabel(comp, " mit Seitenstil ");
			
			comboPageMaster = new Combo(comp, SWT.NONE);
			comboPageMaster.setLayoutData(getGD(0, 2, 140, 0));
			comboPageMaster.setItems(RuntimeUtil.getInstance().getCurrentPrintProject().getPageMasterGroup().getItemNames());
			comboPageMaster.select(0);
			
			Button inheritButton = new Button(comp, SWT.CHECK);
			inheritButton.setText(GuiMessages.Stileditor_Gui_Inherit);
			inheritButton.setLayoutData(getGD(0, 1, 0, 0));

			// add Standard Checkbox
			Button standardButton = new Button(comp, SWT.PUSH);
			standardButton.setText(GuiMessages.Stileditor_Gui_Standard);
			standardButton.setLayoutData(getGD(0, 2, 0, 0));

			// set Standard Checkbox und controlsvalue
			HashMap<String, Control[]> hm = new HashMap<String, Control[]>();
			hm.put("break-after", new Control[] { comboOpenNewpage });
			
			controlsInit(standardButton, inheritButton, hm, null,
					formatForSetup);
		}
		
		{
			
		}
		
		comp.layout();
	}

	/*
	 * Einstellungswerte lesen und Format aktualisieren
	 */
	public Format getFormat() {
		String s = null;
		String attrName;
		// wenn Format standardwerte übernehmen soll, werde mit
		// standardReference
		// gespeichert.
		String standardReference = "%@%";
		boolean isFormatStandard = false;

		if (this.format.getType().equals("standard")) {
			standardReference = "";
			isFormatStandard = true;
		}

		{// Ausrichtung
			attrName = "text-align";

			s = readCombo(comboAlignment);
			s = getOriginalValue(attrName, s);

			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!comboAlignment.isEnabled() || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}

			/*
			 * if (!comboAlignment.isEnabled()) s = standardReference; else { s
			 * = readCombo(comboAlignment); s = getOriginalValue(attrName, s); }
			 */

			this.format.setAttribute(attrName, s);
		}

		{// Links
			attrName = "margin-left";

			s = readSpinnerCombo(spinnerMarginLeft, comboMarginLeftUnit);

			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!spinnerMarginLeft.isEnabled() || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}

			/*
			 * if (!spinnerMarginLeft.isEnabled()) s = standardReference; else s
			 * = readSpinnerCombo(spinnerMarginLeft, comboMarginLeftUnit,
			 * factor);
			 */

			this.format.setAttribute(attrName, s);
		}

		{// Recths
			attrName = "margin-right";
			s = readSpinnerCombo(spinnerMarginRight, comboMarginRight);

			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!spinnerMarginRight.isEnabled() || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}

			/*
			 * if (!spinnerMarginRight.isEnabled())
			 * 
			 * s = standardReference; else s =
			 * readSpinnerCombo(spinnerMarginRight, comboMarginRight, factor);
			 */
			this.format.setAttribute(attrName, s);
		}

		{// Sondereinzug
			attrName = "text-indent";
			s = readSpinnerCombo(spinnerSpecialIndent, comboSpecialIndent);

			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!spinnerSpecialIndent.isEnabled() || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}
			/*
			 * if (!spinnerSpecialIndent.isEnabled()) s = standardReference;
			 * else s = readSpinnerCombo(spinnerSpecialIndent,
			 * comboSpecialIndent, factor);
			 */

			this.format.setAttribute(attrName, s);
		}

		{
			// Before Optimum
			attrName = "space-before.optimum";
			s = readSpinnerCombo(spinnerSpacingBeforeOptimum,
					comboSpacingBeforeOptimumUnit);

			boolean isBeforeOptimumEnabled = spinnerSpacingBeforeOptimum
					.isEnabled();

			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}
			if (!isBeforeOptimumEnabled || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}
			this.format.setAttribute(attrName, s);

			/*
			 * Disabled till feature is supported by engine // Before Maximum
			 * attrName = "space-before.maximum"; s =
			 * readSpinnerCombo(spinnerSpacingBeforeMaximum,
			 * comboSpacingBeforeMaximumUnit); if (!isBeforeOptimumEnabled) { s
			 * = standardReference; } else if
			 * (spinnerSpacingBeforeMaximum.isEnabled()) { if (!isFormatStandard
			 * && s.equals(this.format.getFormatGroup()
			 * .getStandardFormat().getAttribute(attrName))) { s =
			 * standardReference; } } else { s = ""; } if
			 * (!isBeforeOptimumEnabled || isFormatStandard) {
			 * this.format.setInherit(attrName, true); } else {
			 * this.format.setInherit(attrName, false); }
			 * this.format.setAttribute(attrName, s);
			 * 
			 * // Before Minimum attrName = "space-before.minimum"; s =
			 * readSpinnerCombo(spinnerSpacingBeforeMinimum,
			 * comboSpacingBeforeMinimumUnit);
			 * 
			 * if (!isBeforeOptimumEnabled) { s = standardReference; } else if
			 * (spinnerSpacingBeforeMinimum.isEnabled()) { if (!isFormatStandard
			 * && s.equals(this.format.getFormatGroup()
			 * .getStandardFormat().getAttribute(attrName))) { // Standard s =
			 * standardReference; } } else { s = ""; } if
			 * (!isBeforeOptimumEnabled || isFormatStandard) {
			 * this.format.setInherit(attrName, true); } else {
			 * this.format.setInherit(attrName, false); }
			 * this.format.setAttribute(attrName, s);
			 */
		}

		{// After Optimum

			attrName = "space-after.optimum";
			s = readSpinnerCombo(spinnerSpacingAfterOptimum,
					comboSpacingAfterOptimumUnit);

			boolean isAfterOptimumEnabled = spinnerSpacingAfterOptimum
					.isEnabled();

			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!isAfterOptimumEnabled || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}
			this.format.setAttribute(attrName, s);

			/*
			 * Disabled till feature is supported by engine // After Maximum
			 * attrName = "space-after.maximum"; s =
			 * readSpinnerCombo(spinnerSpacingAfterMaximum,
			 * comboSpacingAfterMaximumUnit);
			 * 
			 * if (!isAfterOptimumEnabled) { s = standardReference; } else if
			 * (spinnerSpacingAfterMaximum.isEnabled()) { if (!isFormatStandard
			 * && s.equals(this.format.getFormatGroup()
			 * .getStandardFormat().getAttribute(attrName))) { // Standard s =
			 * standardReference; } } else { s = ""; } if
			 * (!isAfterOptimumEnabled || isFormatStandard) {
			 * this.format.setInherit(attrName, true); } else {
			 * this.format.setInherit(attrName, false); }
			 * this.format.setAttribute(attrName, s);
			 * 
			 * // After Minimum attrName = "space-after.minimum"; s =
			 * readSpinnerCombo(spinnerSpacingAfterMinimum,
			 * comboSpacingAfterMinimumUnit); if (!isAfterOptimumEnabled) { s =
			 * standardReference; } else if
			 * (spinnerSpacingAfterMinimum.isEnabled()) { if (!isFormatStandard
			 * && s.equals(this.format.getFormatGroup()
			 * .getStandardFormat().getAttribute(attrName))) { // Standard s =
			 * standardReference; } } else { s = ""; } if
			 * (!isAfterOptimumEnabled || isFormatStandard) {
			 * this.format.setInherit(attrName, true); } else {
			 * this.format.setInherit(attrName, false); }
			 * this.format.setAttribute(attrName, s);
			 */
		}
		
		{
			attrName = "break-after";

			s = readCombo(comboOpenNewpage);
			s = getOriginalValue(attrName, s);
			
			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!comboOpenNewpage.isEnabled() || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}

			this.format.setAttribute(attrName, s);
		}
		
		{
			attrName = "pagemaster";

			s = readCombo(comboPageMaster);
			
			if (!isFormatStandard
					&& s.equals(this.format.getFormatGroup()
							.getStandardFormat().getAttribute(attrName))) { // Standard
				s = standardReference;
			}

			if (!comboPageMaster.isEnabled() || isFormatStandard) {
				this.format.setInherit(attrName, true);
			} else {
				this.format.setInherit(attrName, false);
			}

			this.format.setAttribute(attrName, s);
		}

		return this.format;
	}

	public Composite getComp() {
		return comp;
	}

	@Override
	public boolean controlValueVertify() {
		// TODO
		return true;

	}

}
